<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\api\logic;

use app\admin\logic\LotteryPlay;
use app\admin\model\Members;
use app\api\error\CodeBase;
use app\api\error\Common as CommonError;
use app\common\logic\UserNotice;
use app\common\model\ApplicationBanker;
use app\common\model\BetsLog;
use app\common\model\BetsLogSubscribe;
use app\common\model\GamblerKing;
use app\common\model\GamblerKingInvestmentUser;
use app\common\model\GameCategory;
use app\common\model\GamesLog;
use app\common\model\Idcard;
use app\common\model\KingAccountLog;
use app\common\model\KingBalanceLog;
use app\common\model\LoginLog;
use app\common\model\Lottery;
use app\common\model\LotteryPlayType;
use app\common\model\LotteryRound;
use app\common\model\Member;
use app\common\model\PlanNumber;
use app\common\model\PlatformPay;
use app\common\model\SweepCode;
use app\common\model\ThirdPlanProgramme;
use app\common\model\UserAccount;
use app\common\model\UserAccountLog;
use app\common\model\UserBlackRecord;
use app\common\model\UserKingInvestment;
use app\common\model\UserLoginAddress;
use app\common\model\UserSms;
use \Firebase\JWT\JWT;
use think\Db;

/**
 * 接口基础逻辑
 */
class ThirdPlan extends PlanBase
{



    /**
     * 登录接口逻辑
     */
    public function login($data = [])
    {

        if(empty($data['username'])){
            return ajaxreturn(1, lang('用户名不能为空'));
        }
        if(empty($data['password'])){
            return ajaxreturn(1, lang('密码不能为空'));
        }
        $member = $this->modelMember->where(['username' => $data['username']])->find();
        if (empty($member)) {
            return ajaxreturn(1, lang('用户未注册'));
        }
        if ($member['is_black'] == 1) {
            return ajaxreturn(1, '账号已封号');
        }
        if ($member['is_login'] == 0) {
            return ajaxreturn(1, lang('您的账户多次输入密码错误已被禁止登录，请知悉,解封时间为') . date('Y-m-d H:i:s', $member['no_login_time']));
        }
        if (data_md5_key($data['password']) !== $member['password']) {
            return ajaxreturn(1, '密码错误');

        }
        $token=$this->tokenSign($member);
        return $token;

    }


    /**
     *获取下注结果接口
     */
    public function lottery_result($data)
    {
        if(empty($data['id'])){
            return ajaxreturn(1, lang('彩种id不能为空'));
        }
        $where['a.status']=1;
        !empty($data['id'])  && $where['a.lottery_id']=$data['id'];
        $this->modelLotteryResult->alias('a');
        $lottery_list=$this->modelLotteryResult->getList($where,'lottery_id,round,number,dateline,day_round','a.id desc');
        return $lottery_list;
    }


    /**
     *获取公告
     */
    public function play_list($data)
    {

        empty($data['cate_id'])  && $data['cate_id']=5;
        empty($data['is_old'])  && $data['is_old']=0;
        $play_type_list=LotteryPlayType::all(['status'=>1]);
        $list=$arr=[];
        foreach ($play_type_list as $k=>$v){
            $arr['name']=$v['name'];
            $arr['id']=$v['id'];
            $arr['list']=LotteryPlay::field('id,name')->where(['cate_id'=>$data['cate_id'],'play_cate_id'=>$v['id'],'is_old'=>$data['is_old'],'status'=>1])->select();
            if($arr['list']){

                $list[]=$arr;
            }
        }
        return $list;
    }


    /**
     *获取余额
     */
    public function get_balance($data){
        if(empty($data['user_token'])){
            return ajaxreturn(1, lang('用户token不能为空'));
        }
        $uid=decoded_user_token($data['user_token'],'member_id');
        $order=GamblerKingInvestmentUser::where(['user_id'=>$uid,'state'=>3])->count();

        if($order>0){
            $king=GamblerKing::get(['user_id'=>$uid]);
            return $king->balance;
        }else{
            $user_account=UserAccount::check(['user_id'=>$uid,'wallet_id'=>1],true);
            return $user_account->balance;
        }

    }



    /**
     *下注
     */
    public function bets_lottery($data){
        if(empty($data['user_token'])){
            return ajaxreturn(1, lang('用户token不能为空'));
        }
        if(empty($data['lottery_id'])){
            return ajaxreturn(1, lang('彩种id不能为空'));
        }
        if(empty($data['play_id'])){
            return ajaxreturn(1, lang('玩法id不能为空'));
        }
        if(empty($data['round'])){
            return ajaxreturn(1, lang('期号不能为空'));
        }
        $play=\app\common\model\LotteryPlay::get($data['play_id']);
        if(!$play){
            return ajaxreturn(1,lang('玩法错误'));
        }
        $lottery=Lottery::get($data['lottery_id']);
        if(!$lottery){

            return ajaxreturn(1,lang('彩种错误'));
        }
        if($lottery['state']==0){

            return ajaxreturn(1,lang('彩种已暂停'));
        }

        $lottery_info=LotteryRound::get(['lottery_id'=>$data['lottery_id'],'round'=>$data['round']]);
        if(!$lottery_info){
            return ajaxreturn(1,lang('期号错误'));
        }
        if($lottery_info['state']==1){
            return ajaxreturn(1,lang('当前期数未开始'));
        }
        if($lottery_info['state']==3){
            return ajaxreturn(1,lang('当前期数已封盘'));
        }
        if(empty($data['lottery_id'])){
            return ajaxreturn(1, lang('彩种id不能为空'));
        }
        if (empty($data['univalent']) || $data['univalent'] <= 0) {
            return ajaxreturn(1,lang('单注金额错误'));

        }

        if (empty($data['mult']) || $data['mult'] <= 0) {
            return ajaxreturn(1,lang('倍数错误'));
        }
        $uid=decoded_user_token($data['user_token'],'member_id');
        if($play->is_old==1){
            $counts=1;
        }else{
            $cate_symbol=$lottery->cate->symbol;
            include_once(ROOT_PATH.'extend/yzwanfa/'.$cate_symbol.'.php');
            $_zhushuyzclass = "Lib\\yzwanfa\\{$cate_symbol}";
            $play_obj= new $_zhushuyzclass();
            $counts=$play_obj->checkzhushu($play->symbol,$data['number']);
            if(empty($counts)){
                return ajaxreturn(1,lang('号码错误'));
            }

        }

        $capitals= $data['univalent']*$counts*$data['mult'];//本金

        if($play->max_consumption>0 && $capitals>$play->max_consumption){
            return ajaxreturn(1,lang('最高投注金额为').$play->max_consumption);

        }
        if($play->min_consumption>0 && $capitals<$play->min_consumption){
            return ajaxreturn(1,lang('最低投注金额为').$play->min_consumption);

        }

        if($play->max_injection>0 && $counts>$play->max_injection){
            return ajaxreturn(1,lang('最高投注注数为').$play->max_injection);
        }
        if($play->total_injection>0 ){
            if($counts>$play->total_injection){
                return ajaxreturn(1,lang('已超过最大投注数'));

            }


        }
        $userinfo=Member::get($uid);
        if(strstr($play->max_reward, '|') && strstr($play->max_reward, '|')){

            $v1 = explode('|', $play->max_reward);  //最大奖金
            $v2 = explode('|', $play->max_reward);  //最小奖金
            $maxjj = "";
            //echo $userinfo['fandian'];exit;
            foreach ($v1 as $j => $val) {
                $maxstr = ((($v1[$j] - $v2[$j]) / getConfig('max_point')) * $userinfo->level['game_return'] + $v2[$j]) . '|';
                $maxjj .= sprintf("%.2f", filter_money($maxstr, 2)) . '|';
            }
            $maxjj = substr($maxjj, 0, -1);
            $rate = $maxjj;
        }elseif($play->max_reward>0 && $play->min_reward>0){

            $maxjj = ($play->max_reward - $play->min_reward>0) / (getConfig('max_point')) * ($userinfo->level['game_return']) + $play->min_reward;
            if (substr(explode('.', $maxjj)[1], 0, 2) == '99') {
                $maxjj = sprintf("%.2f", ceil($maxjj));
            } else {
                $maxjj = sprintf("%.2f", filter_money($maxjj, 2));
            }
            $rate = $maxjj;
        }else{

            $rate=$play->mult/getConfig('max_point')* $userinfo->level['game_return'];

        }
        $rate=format_money($rate,4);
        $data['playid']=$play->symbol;
        $data['is_old']=$play->is_old;
        $data['money']=$capitals;
        $data['injection_number']=$counts;
        $data['cate_symbol']=$lottery->cate->symbol;
        $data['third_lottery_id']=$lottery['third_lottery_id'];
        if($play['is_old']==1){
            $data['class2']=LotteryPlay::where(['id'=>$data['play_id']])->value('name');

        }
        $number=explode('|',$data['number']);
//        $code_number=0;
//        foreach ($number as $k=>$v ){
//            $number_next=explode(',',$v);
//            $code_number+=count($number_next);
//        }
//
        $data['entrust_count']=0;
        $data['user_investment_id']=0;
        $app_info=ApplicationBanker::get(1);
//        if (0) {
//
//            $rate = $rate -    sprintf("%.2f",round($play->mult) / 100 * 0);
//
//        }
        Db::startTrans();
        try{
            $member=Member::get($uid);
    //        if(!empty($data['is_simulation']) || $member['is_plan']==1 ){
                //模拟下注
                //当前期数同步下注
                $arr = array(
                    'user_id'=>$uid,
                    'lottery_id'=>$data['lottery_id'],
                    'play_id'=>$play['id'],
                    'round'=>$data['round'],
                    'number'=>$data['number'],
                    'injection_number'=>$counts,
                    'mult'=>$data['mult'],
                    'univalent'=>$data['univalent'],
                    'state'=>1,//1待开奖  2中奖 3:未中
                    'money'=>$capitals,   //本金
                    'create_time'=>TIME_NOW,
                    'odds'=>$rate,
                    'point_odds'=>0,
                    'return_point_money'=>0,
                    'is_old'=>$play->is_old,

                );


                $arr['is_plan']=$member['is_plan'];

                if($member['is_plan']==1){
                    $third_plan=\app\common\model\ThirdPlan::get(['user_id'=>$uid,'symbol'=>$member['username'].'-'.$data['plan_name']]);
                    !empty($data['plan_name']) && $arr['plan_name']=$data['plan_name'];
                    if(!$third_plan){

                        $re=\app\common\model\ThirdPlan::create([
                            'title'=>$member['username'].'-'.$data['plan_name'],
                            'symbol'=>$member['username'].'-'.$data['plan_name'],
                            'user_id'=>$member['id'],
                            'lottery_id'=>$data['lottery_id'],
                            'play_id'=>$data['play_id'],
                            'code_number'=>$counts,
                            'status'=>0
                        ]);
                        $plan_id=$re->id;
                    }else{
                        $plan_id=$third_plan->id;
                    }
                    $arr['plan_id']=$plan_id;
                    $lottery_info=BetsLogSubscribe::get(['create_time'=>['between',[getTodayStart(),TIME_NOW]],'plan_id'=>$plan_id,'round'=>$data['round'],'lottery_id'=>$data['lottery_id'],'is_plan'=>1]);
                    if($lottery_info){
                        return ajaxreturn(1,lang('一个方案一期只能下一注'));
                    }
                    $roud=substr($data['round'],-3)+0;
                    if($roud+2>=$lottery['round_number']){
                        $end_round=$lottery['round_number'];

                    }else{
                        $end_round=$roud+2;
                    }
                    $end_rond_new=$data['round']+$end_round-$roud;
                    $number_info=PlanNumber::get(['create_time'=>['between',[getTodayStart(),TIME_NOW]],'plan_id'=>$plan_id,'play_id'=>$data['play_id'],'state'=>1,'lottery_id'=>$data['lottery_id'],'end_number'=>['<=',$end_round]]);
                    $end_round_info=LotteryRound::get(['lottery_id'=>$data['lottery_id'],'round'=>$end_rond_new]);
                    if($number_info){

                        $count=BetsLogSubscribe::where(['plan_number_id'=>$number_info['id'],'state'=>1])->count();
                        if($count>0){
                            return ajaxreturn(1,lang('上期未结算'));
                        }
                        $plan_number_id=$number_info['id'];
                    }else{
                        $id=PlanNumber::create([
                            'play_id'=>$data['play_id'],
                            'plan_id'=>$plan_id,
                            'first_number'=>$roud,
                            'end_number'=>$end_round,
                            'end_time'=>$end_round_info->getData('end_time'),
                            'number'=>$data['number'],
                            'code_number'=>$counts,
                            'round'=>3,
                            'lottery_id'=>$data['lottery_id']
                        ]);
                        $plan_number_id=$id->id;
                    }
                    $arr['plan_number_id']=$plan_number_id;





                }
                BetsLogSubscribe::create($arr);
                Db::commit();
                return ajaxreturn(0,'下注成功');
            }catch (\Exception $e){
                    Db::rollback();
                    return ajaxreturn(1,$e->getMessage());
            }
//        }else{
//            //真实下注
//            $order=GamblerKingInvestmentUser::where(['user_id'=>$uid,'state'=>3])->find();
//            Db::startTrans();
//            try{
//                if($order){
//                    $king=GamblerKing::get(['user_id'=>$uid]);
//                    if($king['balance']<$capitals){
//
//                        return ajaxreturn(1,lang('余额不足'));
//                    }
//                    $capitals_entrust=$capitals*$order->order_count;
//                    if($king['king_win_account']<$capitals_entrust){
//                        return ajaxreturn(1,lang('委托可用余额不足'));
//                    }
//
////                     $res=$this->third_bets($data);
////                     if(!$res ){
////                         return ajaxreturn(1,lang('下注失败'));
////                     }
////                     if($res['code']!=0 ){
////                         return ajaxreturn(1,$res['message']);
////
////                     }
//                    $dat = array(
//                        'user_id'=>$uid,
//                        'lottery_id'=>$data['lottery_id'],
//                        'play_id'=>$play->id,
//                        'round'=>$data['round'],
//                        'number'=>$data['number'],
//                        'injection_number'=>$counts,
//                        'user_investment_id'=>$order['id'],
//                        'mult'=>$data['mult'],
//                        'univalent'=>$data['univalent'],
//                        'entrust_count'=>0,
//                        'king_id'=>$king['id'],
//                        'state'=>1,//1待开奖  2中奖 3:未中
//                        'money'=>$capitals,   //本金
//                        'create_time'=>TIME_NOW,
//                        'odds'=>$rate,
//                        'point_odds'=>0,
//                        'return_point_money'=>0,
//                        'is_old'=>$play->is_old,
//                        'trade_no'=>'BT'.date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8).rand(1000,9999),
//
//                    );
//
//                    $dats[]=$dat;
//
//                    //赌王下注
//                    $game=[
//                        'user_id'=>$uid,
//                        'king_id'=>$king['id'],
//                        'user_investment_id'=>$order['id'],
//                        'investment_id'=>0,
//                        'type'=>4,
//                        'entrust_count'=>$order->order_count,
//                        'state'=>3,
//                        'order_no'=>$dat['trade_no'],
//                        'number'=>$capitals,
//                        'create_time'=>TIME_NOW,
//                        'users'=>'',
//                        'app_id'=>0,
//                        'remark'=>'',
//                        'bet_username'=>'',
//                        'king_number'=>0
//
//                    ];
//
//
////                     $arr=[
////                         'user_id'=>$uid,
////                         'king_id'=>$king['id'],
////                         'user_investment_id'=>$order['id'],
////                         'investment_id'=>0,
////                         'type'=>1,
////                         'entrust_count'=>$order->order_count,
////                         'state'=>1,
////                         'order_no'=>$dat['trade_no'],
////                         'number'=>$capitals,
////                         'create_time'=>TIME_NOW,
////                         'users'=>'',
////                         'app_id'=>$app_info['id'],
////                         'remark'=>$res['message'],
////                         'bet_username'=>$app_info['username'],
////                         'king_number'=>format_money( ($app_info['return_point']-$userinfo->level->game_return)/100*$capitals,2 )
////
////
////                     ];
//                    $userids=UserKingInvestment::where(['user_investment_id'=>$order['id'],'state'=>6])->column('user_id');
//                    if($userids){
//                        foreach ($userids as $k=>$v){
//                            $investment_bet_log=[
//                                'create_time'=>TIME_NOW,
//                                'user_investment_id'=>$order['id'],
//                                'user_id'=>$v,
//                                'type'=>1,
//                                'trade_no'=>$dat['trade_no'],
//                                'number'=>$capitals/($order->order_count+1)
//                            ];
//                            $investment_bet_logs[]=$investment_bet_log;
//                        }
//                    }else{
//                        $investment_bet_logs=[];
//                    }
//                    $investment_bet_log=[
//                        'create_time'=>TIME_NOW,
//                        'user_investment_id'=>$order['id'],
//                        'user_id'=>$order->user_id,
//                        'type'=>2,
//                        'trade_no'=>$dat['trade_no'],
//                        'number'=>$capitals/($order->order_count+1)
//                    ];
//                    $investment_bet_logs[]=$investment_bet_log;
//                    if(!empty($investment_bet_logs)){
//                        Db::name('investment_bet_log')->insertAll($investment_bet_logs);
//                    }
//                    $arrs[]=$game;
////                    $arrs[]=$arr;
//                    $king->king_win_account-=$capitals;
//                    $king->save();
//                    //写入流水
//                    KingBalanceLog::create([
//                        'user_id'=>$uid,
//                        'king_id'=>$king['id'],
//                        'number'=>$capitals,
//                        'is_add'=>2,
//                        'remark'=>'赌王挂机下注'.$data['round'].'期',
//                        'type'=>1
//                    ]);
//                    Db::name('games_log')->insertAll($arrs);
//                    Db::name('bets_log')->insertAll($dats);
//                    Db::commit();
//                    return ajaxreturn(0,'下注成功');
//                }else{
//
//                    $user_account=UserAccount::check(['user_id'=>$uid,'wallet_id'=>1],false);
//                    if($user_account['balance']<$capitals){
//                        return ajaxreturn(1,lang('余额不足'));
//                    }
////                     $res=$this->third_bets($data);
////                     if(!$res){
////                         return ajaxreturn(1,lang('下注失败'));
////                     }
////
////                     if($res['code']!=0){
////                         return ajaxreturn(1,$res['message']);
////
////                     }
//
//                    $user_account->balance-=$capitals;
//                    $user_account->save();
//                    //写入流水
//                    UserAccountLog::create([
//                        'user_id'=>$uid,
//                        'wallet_id'=>1,
//                        'before_blance'=>$user_account->balance+$capitals,
//                        'after_blance'=>$user_account->balance,
//                        'remark'=>'用户挂机下注'.$data['round'].'期',
//                        'number'=>$capitals,
//                        'type'=>29,
//                        'is_add'=>2,
//                    ]);
//                    $dat = array(
//                        'user_id'=>$uid,
//                        'lottery_id'=>$data['lottery_id'],
//                        'play_id'=>$play->id,
//                        'round'=>$data['round'],
//                        'number'=>$data['number'],
//                        'injection_number'=>$counts,
//                        'user_investment_id'=>0,
//                        'mult'=>$data['mult'],
//                        'univalent'=>$data['univalent'],
//                        'entrust_count'=>0,
//                        'king_id'=>0,
//                        'state'=>1,//1待开奖  2中奖 3:未中
//                        'money'=>$capitals,   //本金
//                        'create_time'=>TIME_NOW,
//                        'odds'=>$rate,
//                        'point_odds'=>0,
//                        'return_point_money'=>0,
//                        'is_old'=>$play->is_old,
//                        'trade_no'=>'BT'.date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8).rand(1000,9999),
//
//                    );
//                    $dats[]=$dat;
//
//                    //赌王下注
//                    $game=[
//                        'user_id'=>$uid,
//                        'king_id'=>0,
//                        'user_investment_id'=>0,
//                        'investment_id'=>0,
//                        'type'=>4,
//                        'entrust_count'=>0,
//                        'state'=>3,
//                        'order_no'=>$dat['trade_no'],
//                        'number'=>$capitals,
//                        'create_time'=>TIME_NOW,
//                        'users'=>'',
//                        'app_id'=>0,
//                        'remark'=>'',
//                        'bet_username'=>'',
//                        'king_number'=>0
//                    ];
//                    $arrs[]=$game;
////                     $arr=[
////                         'user_id'=>$uid,
////                         'king_id'=>0,
////                         'user_investment_id'=>0,
////                         'investment_id'=>0,
////                         'type'=>1,
////                         'entrust_count'=>0,
////                         'state'=>1,
////                         'order_no'=>$dat['trade_no'],
////                         'number'=>$capitals,
////                         'create_time'=>TIME_NOW,
////                         'users'=>'',
////                         'app_id'=>$app_info['id'],
////                         'remark'=>$res['message']
////
////                     ];
//                     $arr['bet_username']=$app_info['username'];
//                     $arr['king_number']=format_money( ($app_info['return_point']-$userinfo->level->game_return)/100*$capitals,2 );
////                     $arrs[]=$arr;
//                    //插入订单
//                    Db::name('games_log')->insertAll($arrs);
//                    Db::name('bets_log')->insertAll($dats);
//                    Db::commit();
//                    return ajaxreturn(0,'下注成功');
//
//                }
//
//            }catch (\Exception $e){
//                Db::rollback();
//                return ajaxreturn(1,$e->getMessage());
//            }
//        }



    }

    public  function  calculate_reward($data){

        $play=LotteryPlay::get($data['play_id']);
        $uid=decoded_user_token($data['user_token'],'member_id');
        $member=Member::get($uid);
        $point = $member->level->game_return;

        if(!$play){
            return ajaxreturn(1,lang('玩法错误'));
        }



        if(strstr($play->max_reward, '|') && strstr($play->max_reward, '|')){

            $v1 = explode('|', $play->max_reward);  //最大奖金
            $v2 = explode('|', $play->max_reward);  //最小奖金
            $maxjj = "";

            foreach ($v1 as $j => $val) {
                $maxstr = ((($v1[$j] - $v2[$j]) / getConfig('max_point')) * $point + $v2[$j]) . '|';
                $maxjj .= sprintf("%.2f", filter_money($maxstr, 2)) . '|';
            }
            $maxjj = substr($maxjj, 0, -1);
            $rate = $maxjj;
        }elseif($play->max_reward>0 && $play->min_reward>0){

            $maxjj = ($play->max_reward - $play->min_reward>0) / (getConfig('max_point')) * ($point) + $play->min_reward;
            if (substr(explode('.', $maxjj)[1], 0, 2) == '99') {
                $maxjj = sprintf("%.2f", ceil($maxjj));
            } else {
                $maxjj = sprintf("%.2f", filter_money($maxjj, 2));
            }
            $rate = $maxjj*$data['univalent'];
        }else{
            $rate=$play->mult/2/getConfig('max_point')* $point;

        }

        return $rate;



    }

    /**
     * 第三方下注
     */

    public static function  third_bets($data){
        $arrs=$arr1s=[];

        $app_info=ApplicationBanker::get(1);
        $cate_symbol=$data['cate_symbol'];
        $data['univalent']=floatval($data['univalent']);
        $arrs[]=$data;

        if($data['is_old']==1){

            include_once(ROOT_PATH.'extend/thirdparty/oldplay.php');
            $_zhushuyzclass = "thirdparty\\oldplay";
            $_obj = new $_zhushuyzclass($arrs);

        }else{
            include_once(ROOT_PATH.'extend/thirdparty/'.$cate_symbol.'.php');
            $_zhushuyzclass = "thirdparty\\{$cate_symbol}";
            $_obj = new $_zhushuyzclass($arrs);

        }

        $res=$_obj->check();
        $dat=[
            'lt_self_commissionrate'=>0,
            'lt_trace_if'=>'no',
            'lt_trace_stop'=>'yes',
            "lt_issue_start"=>$data['round'],
            'lt_combuy_check'=>0
        ];
        $dat['OrderDataList']=$res;
        $TraceDataList=[
            [
                'lt_trace_issues'=>1,
                'lt_trace_Times'=>0
            ]
        ];
        $dat['TraceDataList']=$TraceDataList;
        if($data['entrust_count']==0){
            $dat['userName']= $app_info['username'];
        }else{
            $dat['userName']= $app_info['pwd'];
        }
        $url='http://bj.testbj.net/api/external/lotterybetting/'.$data['third_lottery_id'];
        $time=TIME_NOW;
        $sign=md5($time.json_encode($dat).'ty25w3f8jkgg1xw633ypkg16');
        $header_sign=$sign.'_'.$time;
        $heades=[
            'X-Signature-Code:'.$header_sign,
        ];

        $res=mycurl($url,json_encode($dat),1,$heades);
        return json_decode($res,true);



    }



    /**
     * JWT验签方法
     */
    public static function tokenSign($member)
    {

        $key = API_KEY . JWT_KEY;

        $jwt_data = ['member_id' => $member['id'], 'create_time' => $member['create_time']];

        $token = [
            "iss"   => "HaoMen JWT",         // 签发者
            "iat"   => TIME_NOW,              // 签发时间
            "exp"   => TIME_NOW + TIME_NOW,   // 过期时间
            "aud"   => 'HaoMen',             // 接收方
            "sub"   => 'HaoMen',             // 面向的用户
            "data"  => $jwt_data
        ];

        $jwt = JWT::encode($token, $key);


        return $jwt;
    }

    /**
     * 退出登录
     */
    public function loginout($data)
    {

        //$member = get_member_by_token($data['user_token']);
        $uid=$this->logicApiBase->member['id'];
        $member_info = $this->logicMember->getMemberInfo(['id' => $uid]);
        $member_info->login_token='';
        $member_info->save();


        return ajaxreturn(0,lang('退出成功'));
    }






}
